package com.myq.note.controller;

import com.myq.note.po.Result;
import com.myq.note.po.User;
import com.myq.note.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    public UserService userService;



    @PostMapping("/login.action")
    public Result login(User user) {


        Result<User> result = userService.loginUser(user);


//        result.setStatus(200);
//        result.setMes("成功");
//        Cookie cookie = new Cookie("username", user.getUsername());
//        cookie.setMaxAge(60 * 60 * 24 * 7);
//        response.addCookie(cookie);
//        session.setAttribute("user", user);

        return result;
    }


    @PostMapping("/register.action")
    public Result register_in(User user) {

        Result result = userService.registerUser(user);


        return result;
    }


}
